#include "stdio.h"
#include "fcntl.h"
#include "errno.h"
#include "unistd.h"
#include "string.h"

int main(int argc, char const *argv[])
{
    // 打开文件  返回值: 文件描述符
    int fd1 = open("test/app_buffer_test1.c", O_RDONLY);
    if (fd1 == -1)
    {
        //printf("open error: %d\n", errno);
        //printf("open error: %s\n", strerror(errno));
        perror("open error");
        return -1;
    }
    int fd2 = open("test/test.c", O_WRONLY | O_CREAT, 0666);
    if (fd2 == -1)
    {
        printf("open error: %d\n", errno);
        return -1;
    }

    char buf[1024];
    ssize_t realLen = 0;
    while ((realLen = read(fd1, buf, 1024)) > 0)
    {
        printf("%.*s", realLen, buf);

        write(fd2, buf, realLen);
    }

    close(fd1);
    close(fd2);


    return 0;
}
